package org.example.completed.controller;

import org.example.completed.domain.Reservation;
import org.example.completed.service.ReservationService;
import org.example.completed.utils.ApiResponse;  // 导入ApiResponse
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/reservations")
public class ReservationController {

    private final ReservationService reservationService;

    @Autowired
    public ReservationController(ReservationService reservationService) {
        this.reservationService = reservationService;
    }

    // 获取所有参观预约信息
    @GetMapping
    public ApiResponse getAllReservations() {
        List<Reservation> reservations = reservationService.getAllReservations();  // 获取预约信息
        return ApiResponse.success(reservations, "获取所有预约信息成功");  // 返回统一格式的成功响应
    }

    // 添加预约
    @PostMapping
    public ApiResponse addReservation(@RequestBody Reservation reservation) {
        reservationService.addReservation(reservation); // 添加预约信息
        return ApiResponse.success(null, "预约成功");  // 返回成功响应
    }
}